<?php
	/*
	Description: This file is used to add new venue.
	*/
	#########IncludeFiles####################################################################################
	include_once '../inc/config.php';
	include_once("../inc/bootstrape.php");
    require_once _SITE_PATH_.'classes/Venue/Venue.php';
	require_once _SITE_PATH_.'classes/Vendor/Vendor.php';
	require_once _SITE_PATH_.'classes/CommonUtility/CommonUtility.php';
    require_once _SITE_PATH_.'classes/Master/Master.php';
		
	if(isset($_POST['submit'])){
		$params=array();
		
		$params['vendor_id'] = $_POST['vendor_id'];
		$params['vendor_services'] = @implode(',',$_POST['vendor_services']);
		$params['venue_name'] = $_POST['venue_name'];
		$params['display_name'] = $_POST['display_name'];
		$params['venue_description'] = $_POST['venue_description'];
		$params['min_capacity'] = $_POST['min_capacity'];
		
		$params['max_capacity'] = $_POST['max_capacity'];
		$params['available_seating'] = $_POST['available_seating'];
		$params['address'] = $_POST['address'];
		$params['country'] = $_POST['country'];
		$params['state'] = $_POST['state'];
		
		$params['city'] = $_POST['city'];
		$params['landmark'] = $_POST['landmark'];
		$params['contact_person'] = $_POST['contact_person'];
		$params['booking_mode'] = $_POST['booking_mode'];
	
		$params['parking'] = $_POST['parking'];
		$params['venue_type'] = $_POST['venue_type'];
		$params['cutoff_days'] = $_POST['cutoff_days'];
		$params['tags'] = $_POST['tags'];
		
		$params['food_type'] = $_POST['food_type'];
		$params['zone'] = $_POST['zone'];
		$params['mobile_no'] = $_POST['mobile_no'];
		$params['landline_phone1'] = $_POST['landline_phone1'];
		$params['landline_phone2'] = $_POST['landline_phone2'];
		
		$params['latitude'] = $_POST['latitude'];
		$params['longitude'] = $_POST['longitude'];
		$params['booking_amount'] = $_POST['booking_amount'];

		$params['cancellation_policy'] = $_POST['cancellation_policy'];
		$params['tc_policy'] = $_POST['tc_policy'];
		
		if(!empty($_POST['similar_venues'])){
			$str_similar_venues = implode(',',$_POST['similar_venues']);
			$params['similar_venues'] = $str_similar_venues;
		}
		
	    // upload and create thumb of the image //
	    if( !empty( $_FILES['venue_image'] ) ){
	        $filename  = 'venue_image';     //  this is name of the control you are using in html form         
	        $module='venue_images';
	        $uploadedfile = CommonUtility::uploadNcreateThumb($filename, $module, true, 100, true);
	        if( $uploadedfile!= -1 )    {
	            $params['venue_image'] = $uploadedfile;//$_POST['venue_image'];
	        }        
	    }
	    	
		$response = CommonUtility::insertData($params,'venues','id');
		
		if(is_int($response)){
			$venue_id = $response;
			
			// upload and create thumb of the image //
			if( !empty($_FILES['venue_images'] ) ){
				$parms_venue_images = array();
				$filename  = 'venue_images';     //  this is name of the control you are using in html form    
				$uploadedfile = CommonUtility::uploadNcreateThumb($filename, $module='venue_images', true, 100, true);
			
				if( $uploadedfile != -1 )    {
					$parms_venue_images['entity_type'] = '2';
					$parms_venue_images['entity_id'] = $venue_id;

					$i = 0;
					foreach($uploadedfile as $key => $val){
						$parms_venue_images['image'] = $val;
						$parms_venue_images['image_title'] = $_POST['image_title'][$i];
                    	$parms_venue_images['image_tooltip'] = $_POST['image_tooltip'][$i];
                    	$parms_venue_images['image_description'] = $_POST['image_description'][$i];
                    	$parms_venue_images['added'] = date("Y-m-d");
						CommonUtility::insertData($parms_venue_images,'site_galleries');
						$i++;
					}
				}
			}
			
			/*if(!empty($_POST['venue_services'])){
				foreach($_POST['venue_services'] as $key => $val){
					$services_params = array();
					$date = date("Y-m-d h:i:s");
					$services_params['venue_id'] = $venue_id;
					$services_params['service_id'] = $val;
					$services_params['added'] = $date;
				
					if(CommonUtility::insertData($services_params,'venue_services')){
						header("Location: venue_mng.php?msg=1334");  
					}
				}
			}*/

			if(!empty($_POST['cbo_cities'])){
	           $i = 0;
	            $params_cities_distance = array();
	            $params_cities_distance['venue_id'] = $venue_id;
	            foreach($_POST['cbo_cities'] as $key => $val){
	                $params_cities_distance['city_id'] = $val;
	                $params_cities_distance['distance'] = $_POST['distance'][$i];
	                 $params_cities_distance['added'] = date("Y-m-d H:i:s");
	                CommonUtility::insertData($params_cities_distance, 'venue_distances');
	                $i++;
	            } 
	        }

			header("Location: venue_mng.php?msg=1334");  
		}
		$err = 1335;
	}

	$editor = CommonUtility::includeEditor();

	
  //$venue_inclusion = Master::getInclusion($_POST['inclusion']);
  //$venue_exclusion = Master::getInclusion($_POST['exclusion']);

	$vendors = array();
	$vendors = Vendor::getVendor();
	
	$venue_type = array();
	$venue_type = Venue::getActiveVenueTypes();
	
	$venue_services = array();
	$venue_services = Venue::getActiveVenueServices();
		
	$venues = array();
	$venues = Venue::getActiveVenues();
	
	$dropdown_zones = "";
	$dropdown_zones = CommonUtility::getZone();
	
	$dropdown_countries = "";
	$dropdown_countries = CommonUtility::getCountry();
	
	$booking_mode = array(1=>"online",2=>"offline",3=>"both");
	
	$food_type = array("veg"=>"Veg","nonveg"=>"Non Veg","both"=>"Both");
	
	$errMsg = $err;
	$_tplName = 'venue/venue_add.tpl';
	$_title = 'Add Venue';
	require_once _ADMIN_TPL_MAIN_;
?>